9a54fc
@@ -704,7 +704,7 @@
public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
     // Interrupt catalog tracker here in case any regions being opened out in
     // handlers are stuck waiting on meta or root.
     if (this.catalogTracker != null) this.catalogTracker.stop();
-    if (this.fsOk) waitOnAllRegionsToClose();
+    if (this.fsOk) waitOnAllRegionsToClose(abortRequested);
 
     // Make sure the proxy is down.
     if (this.hbaseMaster != null) {
@@ -783,7 +783,7 @@
public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
   /**
    * Wait on regions close.
    */
-  private void waitOnAllRegionsToClose() {
+  private void waitOnAllRegionsToClose(final boolean abort) {
     // Wait till all regions are closed before going out.
     int lastCount = -1;
     while (!isOnlineRegionsEmpty()) {
@@ -798,6 +798,16 @@
public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler,
           LOG.debug(this.onlineRegions);
         }
       }
+      // Ensure all user regions have been sent a close. Use this to
+      // protect against the case where an open comes in after we start the
+      // iterator of onlineRegions to close all user regions.
+      for (Map.Entry<String, HRegion> e : this.onlineRegions.entrySet()) {
+        HRegionInfo hri = e.getValue().getRegionInfo();
+        if (!this.regionsInTransitionInRS.contains(hri.getEncodedNameAsBytes())) {
+          // Don't update zk with this close transition; pass false.
+          closeRegion(hri, abort, false);
+        }
+      }
       Threads.sleep(1000);
     }
   }
